<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover">
    <title>登录</title>
    <link rel="stylesheet" href="../../static/login/css/login.css" th:src="@{/static/login/css/login.css}"/>
    <script type="text/javascript" src="../../static/easyui/jquery.min.js" th:src="@{/static/easyui/jquery.min.js}"></script>
</head>
<body>
<div class="login_container">
    <div class="header_contaimer">
        <div class="return_home">

        </div>
    </div>
    <div class="message_container">
        <div class="login_indow">
            <div class="logo_box">
                <img src="/static/login/images/login.svg" alt=""><span class="message"></span>
            </div>

            <form id="formLogin" method="post">
                <input type="hidden" id="loginKey" name="loginKey" th:value="${LOGIN_KEY}"/>
                <div id="divMessage" style="width:100%;text-align:center;padding-top:30px;padding-bottom:5px;color: red;"></div>
                <div class="input_box">
                    <input id="code" name="code" type="text" aria-describedby="code-addon" required="true" maxlength="30" class="form-control" placeholder="请输入用户名">
                </div>
                <div class="input_box">
                    <input id="password" name="password" type="password" aria-describedby="password-addon" required="true" minlength="4" maxlength="15" class="form-control" placeholder="请输入密码">
                    <!-- <div class="input-group-addon obtain" style="background:#fff !important;height:40px;line-height:40px;vertical-align:bottom;"></div> -->
                </div>
                <div class="input_box">
                    <input id="captcha" name="captcha" type="text" aria-describedby="captcha-addon" required="true" minlength="4" maxlength="6" class="form-control input_code" placeholder="请输入图片验证码">
                    <div class="input-group-addon obtaincap" style="background:#fff;">
                        <img id="captchaImage" src="/captcha/index.do" alt="点击更换" title="点击更换">
                    </div>
                </div>


                <button id="btnLogin" type="button" class="sign_btn" style="cursor: pointer; color: #fff;">登录</button>
                <div id="divPolicy" class="input_box" style="display: none;">
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    var loginCount=0;
    document.onkeydown=function(event){
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if(e && e.keyCode==13){
            $("#btnLogin").click();
        }
    };

    $(document).ready(function () {
        if (top.location != location) {
            top.location.href = location.href;
        }

        //更换验证码
        $("#captchaImage").click(function() {
            $("#captchaImage").attr("src", "/captcha/index.do?t="+ (new Date().getTime()));
        });

        //提交表单
        $("#btnLogin").click(function() {
            if(loginCount>5){
                $("#divMessage").html("累计登录超过5次,请刷新页面");
                return;
            }
            if($("#code").val()==""){
                $("#divMessage").html("请输入用户名");
                $("#code").focus();
                return;
            }else if($("#password").val()==""){
                $("#divMessage").html("请输入密码");
                $("#password").focus();
                return;
            }else if($("#captcha").val()==""){
                $("#divMessage").html("请输入验证码");
                $("#captcha").focus();
                return;
            }else {
                $.ajax({
                    url: "/login/authentication.do",
                    dataType: "json",
                    data: $("#formLogin").serialize(),
                    type: "post",
                    success: function (res) {
                        if (res.code != 0) {
                            loginCount++;
                            $("#divMessage").html(res.result);
                            $("#captchaImage").attr("src", "/captcha/index.do?t="+ (new Date().getTime()));
                        }else{
                            if(res.result.token!=""){
                                localStorage.removeItem("expireTime");
                                localStorage.removeItem("Authorization");
                                localStorage.setItem("expireTime",res.result.expireTime);
                                localStorage.setItem("Authorization",res.result.token);
                            }
                            window.location.href = res.result.url;
                        }
                    },
                    error: function (res) {
                        $("#divMessage").html("操作失败，联系统管理员");
                    }
                });
            }
        });
    });



</script>

</body></html>